package cn.cqone.crm.controller;

import cn.cqone.crm.domain.Customer;
import cn.cqone.crm.domain.CustomerTraceHistory;
import cn.cqone.crm.query.CustomerTraceHistoryQuery;
import cn.cqone.crm.service.CustomerService;
import cn.cqone.crm.service.CustomerTraceHistoryService;
import cn.cqone.crm.utils.JSONResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@ResponseBody
@RequestMapping("/cusTraHistory")
@CrossOrigin
@RequiresPermissions("customer_trace_history:main")
public class CustomerTraceHistoryController extends BaseController<CustomerTraceHistory,Long,CustomerTraceHistoryQuery> {

    @Autowired
    private CustomerService customerService;

    @Autowired
    private CustomerTraceHistoryService customerTraceHistoryService;

    //跟进
    @RequestMapping(value = "/moveCus/{id}",method = RequestMethod.POST)
    public JSONResult moveCus(@RequestBody CustomerTraceHistory customerTraceHistory,
                              @PathVariable("id") Long id){
        try{
            Customer customer = customerService.findById(id);
            customerService.moveTrace(customer);
            customerTraceHistory.setCustomer_id(customer);
            customerTraceHistoryService.add(customerTraceHistory);
            return JSONResult.ok();
        }catch (Exception e){
            e.printStackTrace();
            return JSONResult.error("修改失败！");
        }
    }

}
